package com.yanqu.road.server.channelserver.cmd.activity.washe;

import com.yanqu.road.entity.activity.washe.data.WasheUserKey;
import com.yanqu.road.entity.enums.washe.eWasheOperateType;
import com.yanqu.road.logic.pb.WashePb2;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheActivity;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;

@Cmd(code = ChannelProtocol.N_WASHE_OPERATE, desc = "")
public class ChannelWasheOperateCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WasheProto.ChannelWasheOperateReqMsg reqMsg = WasheProto.ChannelWasheOperateReqMsg.parseFrom(packet.getBytes());
        WasheUserKey userKey = WashePb2.parseWasheUserKey(reqMsg.getUserKey());

        ChannelWasheActivity activity = ChannelWasheMgr.getActivity(userKey.getChannelId());
        if (activity == null) {
            log.error("can not find washe activity! channelId {}.", userKey.getChannelId());
            return true;
        }

        WasheProto.WasheOperateReqMsg req = reqMsg.getReq();
        long showNo = -1;
        if (req.hasShowNo()) {
            showNo = req.getShowNo();
        }

        if (req.getType() == eWasheOperateType.Move.getValue()) {
            activity.moveByCmd(userKey, WashePb2.parseWasheMoveParam(req), showNo);
        } else if (req.getType() == eWasheOperateType.UseCard.getValue()) {
            activity.useCardByCmd(userKey, WashePb2.parseWasheUseSkillParam(req), showNo);
        } else if (req.getType() == eWasheOperateType.UseSkill.getValue()) {
            activity.useSkillByCmd(userKey, WashePb2.parseWasheUseSkillParam(req), showNo);
        } else if (req.getType() == eWasheOperateType.SendExpression.getValue()) {
            activity.sendExpressionByCmd(userKey, req.getExpressionId());
        } else if (req.getType() == eWasheOperateType.EndGuide.getValue()) {
            activity.guideSuccessByCmd(userKey);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
